		<?php $this->load->view('layout/lib_chart');?>
		
		
		<?php 
			$maxheight=$row["sum_assured_death"];
			if ($row["sum_assured_disability"] > $maxheight)$maxheight = $row["sum_assured_disability"];
			if ($row["sum_assured_critical_illness"] > $maxheight)$maxheight = $row["sum_assured_critical_illness"];
			$pit=$row["policy_incepted"]+$row["policy_term"];
			$policy_incepted	=	$row["policy_incepted"];
			$maxheight+=($maxheight*0.1);
			$current_year	=	date('Y');
		?>
		<!-- 2. Add the JavaScript to initialize the chart on document ready -->
			<script type="text/javascript">
			var chart1,chart2,chart3,chart4;
			$(document).ready(function() {
				chart1 = new Highcharts.Chart({
					chart: {
						renderTo: 'container1',
						defaultSeriesType: 'spline',
						inverted: true,
						width: 400,
						style: {
							//margin: '0 auto'
						}
					},
					title: {
						text: 'Protection'
					},
					subtitle: {
						//text: 'According to the Standard Atmosphere Model'
					},
					xAxis: {
						reversed: false,
						title: {
							enabled: true,
							text: 'SAD'
						},
						labels: {
							formatter: function() {
								return this.value +'';
							}
						},
						maxPadding: 0.05,
						//showLastLabel: true,
						min : 0,
						max : <?php echo $maxheight;?>
					},
					yAxis: {
						title: {
							text: 'PI + t'
						},
						labels: {
							formatter: function() {
								return this.value + '';
							}
						},
						lineWidth: 1,
						gridLineWidth : 0,
						plotLines: [{
				            color: 'green',
				            width: 1,
				            value: <?php echo $current_year;?>,
				           	dashStyle: 'dash'
				        },
				        {
				            color: 'green',
				            width: 1,
				            value: <?php echo $pit;?>,
				           	dashStyle: 'dash'
				        }
				        ],
						min : <?php echo $current_year;?>,
						//categories:['2011','2040','2050']
					},
					legend: {
						enabled: false
					},
					tooltip: {
						formatter: function() {
							return ''+
								this.y +' / '+ this.x +'';
						}
					},
					plotOptions: {
						spline: {
							marker: {
								enable: false
							}
						}
					},
					series: [{
						name: 'Temperature',
						data: [[<?php echo $row["sum_assured_death"];?>, <?php echo $current_year;?>], [<?php echo $row["sum_assured_death"];?>, <?php echo $pit;?>]]
						//data:[90000,90000,90000]
					}]
				});

				chart2 = new Highcharts.Chart({
					chart: {
						renderTo: 'container2',
						defaultSeriesType: 'spline',
						inverted: true,
						width: 400,
						style: {
							//margin: '0 auto'
						}
					},
					title: {
						text: 'Protection'
					},
					subtitle: {
						//text: 'According to the Standard Atmosphere Model'
					},
					xAxis: {
						reversed: false,
						title: {
							enabled: true,
							text: 'SADI'
						},
						labels: {
							formatter: function() {
								return this.value +'';
							}
						},
						maxPadding: 0.05,
						//showLastLabel: true,
						min : 0,
						max : <?php echo $maxheight;?>
					},
					yAxis: {
						title: {
							text: 'PI + t'
						},
						labels: {
							formatter: function() {
								return this.value + '';
							}
						},
						lineWidth: 2,
						min : <?php echo $current_year;?>,
						gridLineWidth : 0,
						plotLines: [{
				            color: 'green',
				            width: 1,
				            value: <?php echo $current_year;?>,
				           	dashStyle: 'dash'
				        },
				        {
				            color: 'green',
				            width: 1,
				            value: <?php echo $pit;?>,
				           	dashStyle: 'dash'
				        }
				        ]
					},
					legend: {
						enabled: false
					},
					tooltip: {
						formatter: function() {
							return ''+
								this.y +' / '+ this.x +'';
						}
					},
					plotOptions: {
						spline: {
							marker: {
								enable: false
							}
						}
					},
					series: [{
						name: 'Temperature',
						data: [[<?php echo $row["sum_assured_disability"];?>, <?php echo $current_year;?>], [<?php echo $row["sum_assured_disability"];?>, <?php echo $pit;?>]]
					}]
				});

				chart3 = new Highcharts.Chart({
					chart: {
						renderTo: 'container3',
						defaultSeriesType: 'spline',
						inverted: true,
						width: 400,
						style: {
							//margin: '0 auto'
						}
					},
					title: {
						text: 'Protection'
					},
					subtitle: {
						//text: 'According to the Standard Atmosphere Model'
					},
					xAxis: {
						reversed: false,
						title: {
							enabled: true,
							text: 'SACI',
							align: 'high'
						},
						labels: {
							formatter: function() {
								return this.value +'';
							}
						},
						maxPadding: 0.05,
						//showLastLabel: true,
						min : 0,
						max : <?php echo $maxheight;?>
					},
					yAxis: {
						title: {
							text: 'PI + t',
							align: 'high'
						},
						labels: {
							formatter: function() {
								return this.value + '';
							}
						},
						gridLineWidth : 0,
						plotLines: [{
				            color: 'green',
				            width: 1,
				            value: <?php echo $current_year;?>,
				           	dashStyle: 'dash'
				        },
				        {
				            color: 'green',
				            width: 1,
				            value: <?php echo $pit;?>,
				           	dashStyle: 'dash'
				        }
				        ],
						lineWidth: 2,
						min : <?php echo $current_year;?>
					},
					legend: {
						enabled: false
					},
					tooltip: {
						formatter: function() {
							return ''+
								this.y +' / '+ this.x +'';
						}
					},
					plotOptions: {
						spline: {
							marker: {
								enable: false
							}
						}
					},
					series: [{
						name: 'Temperature',
						data: [[<?php echo $row["sum_assured_critical_illness"];?>, <?php echo $current_year;?>], [<?php echo $row["sum_assured_critical_illness"];?>, <?php echo $pit;?>]]
					}]
				});
				/*
				var chart = new Highcharts.Chart({
				    chart: {
				        renderTo: 'test'
				    },
				    
				    xAxis: {
				        categories: ["2011", "2040"],
				        
				        labels: {
				            formatter: function() {
				                return this.value ;
				            }
				        },
				        //min : 2010,
				        //max : 2050,
				        //tickLength:10
				    },
				    yAxis:{
				    	gridLineWidth:0,
				    	labels: {
				            formatter: function() {
				                return this.value ;
				            }
				        },
				    	max: 200000
					},
				    
				    series: [{
				        data: [90000,90000]        
				    }]
				});*/
				
			});
			</script>
			<?php 
			if($row['consider_cash_value_retirement'] == 1):
				$birth	=	$_SESSION['customer']['date_of_birth'];
				$y_birth	=	date('Y',strtotime($birth));
				$MY	=	$y_birth	+	$row['retirement_age'];
				$y_max	=	$row['policy_incepted']	+	$row['policy_term'];
				$Y = array();
				$y	=	0;
				$ar	=	$row["expected_annual_return"]/100;
				$MV	=	$row['cva_retirement'];
				$year_get	=	$y_birth + 100;
				//echo $MY;
				//echo $y_max;
				for($n=$MY; $n <= $year_get; $n+=5){
					//echo $n;
					$x	=	$n;
					$y	=	$MV*pow((1+$ar),($n-$MY));
					$y	=	round($y);
					$temp	=	array($x,$y);
					$Y[]	=	$temp;
					
					//
					$y_plot_line	=	array(
						'value'	=>	$n,
						'dashStyle'	=> 'dash',
						'width'	=> 1,
						'color'	=>	'green',
						'label'	=>array(
							'align'	=>	'right',
							'y'	=>	12,
							'x'	=>	0
							)
					);
					$Y_plot_line[]=$y_plot_line;
					$X_plot_line[]=array(
						'value'	=>	$y,
						'dashStyle'	=> 'dash',
						'width'	=> 1,
						'color'	=>	'green',
						'label'	=>array(
							'align'	=>	'right',
							'y'	=>	12,
							'x'	=>	0
							)
					);
				}
				//$Y	=	array(array(2010,2000),array(2011,2200));
				$Y	=	json_encode($Y);
				$Y_plot_line	=	json_encode($Y_plot_line);
				$X_plot_line	=	json_encode($X_plot_line);
				//print_r($Y);
				//print_r($Y_plot_line);
			?>
			<script type="text/javascript">
			var chart;
			$(document).ready(function() {
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'retirement',
						defaultSeriesType: 'spline',
						//inverted: true,
						width: 800,
						style: {
							margin: '0 auto'
						}
					},
					title: {
						text: ''
					},
					subtitle: {
						text: ''
					},
					xAxis: {
						reversed: false,
						title: {
							enabled: true,
							text: 'Years'
						},
						labels: {
							formatter: function() {
								return this.value +'';
							}
						},
						maxPadding: 0.05,
						min : 2010,
						max :<?php echo $y_max+5;?>,
						plotLines : <?php echo $Y_plot_line;?>,
						//showLastLabel: true,
						//categories:['2010','2011','2012']
					},
					yAxis: [
							{
						title: {
							text: 'Retirement'
						},
						labels: {
							formatter: function() {
								return this.value + '$';
							}
						},
						maxPadding: 0.05,
						lineWidth: 1,
						plotLines : <?php echo $X_plot_line;?>,
						gridLineWidth : 0
						}
					],
					legend: {
						enabled: false
					},
					tooltip: {
						formatter: function() {
							return ''+
								this.x +' : '+ this.y +'';
						}
					},
					plotOptions: {
						spline: {
							marker: {
								enable: false
							}
						}
					},
					point:{
						sliced: false,
						color: '#fff'
					},
					series: [
					{
						name: 'FD',
						data: <?php echo $Y;?>,
						type: 'line',
						marker:{symbol: '',radius: 2}
					}
					]
				});
				
				
			});
			</script>
			<?php endif;?>
				
		
		<!-- 3. Add the container -->
		<div>Existing coverage <?php echo $param?></div>
		<table>
			<tr>
				<td><div id="container1" style="width: 400px; height: 400px; margin: 0 auto"></div></td>
				<td><div id="container2" style="width: 400px; height: 400px; margin: 0 auto"></div></td>
				
			</tr>
			<tr>
				<td><div id="container3" style="width: 400px; height: 400px; margin: 0 auto"></div></td>
				<td><div id="retirement" style="width: 400px; height: 400px; margin: 0 auto"></div></td>
			</tr>
		</table>
		
